package com.example.binpacking.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.binpacking.model.Interviewer;
import com.example.binpacking.model.Sysmaster;
import com.example.binpacking.model.dto.IndividualDto;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SysmasterMapper extends BaseMapper<Sysmaster> {

    @Insert("INSERT INTO tbl_login_sysmaster (loginid, password,orderid)\n" +
            "SELECT MAX(orderid) + 1 + 10000000000, MAX(orderid) +1 + 10000000000,MAX(orderid) +1\n" +
            "FROM tbl_login_sysmaster;")
    int insert();

    @Select("SELECT * FROM tbl_login_sysmaster\n" +
            "ORDER BY orderid DESC\n" +
            "LIMIT 1;")
    Sysmaster selectByMaxOrderId();

    @Update("UPDATE tbl_login_sysmaster SET name = #{name}, phone = #{phone}, email = #{email} WHERE loginid = #{loginid}")
    int updateUser(@Param("loginid") String loginid, @Param("name") String name, @Param("phone") String phone, @Param("email") String email);

    @Select("SELECT password, loginid, orderid, phone, name, createdate, isdeleted, email, parentid FROM tbl_login_sysmaster WHERE loginid = #{loginid}")
    List<Map<String, Object>> selectUserDetails(@Param("loginid") String loginid);

    @Update("UPDATE tbl_login_sysmaster SET password = #{newkey} WHERE loginid = #{loginid} AND password = #{originalkey}")
    int updatePassword(@Param("loginid") String loginid, @Param("originalkey") String originalkey, @Param("newkey") String newkey);
}
